import React from 'react';
import ReactDOM from 'react-dom';

import { createHashHistory } from 'History';

import { Router, Route, useRouterHistory, IndexRedirect } from 'react-router';

import { syncHistoryWithStore, RouterStore } from 'mobx-react-router';

import { Provider } from 'mobx-react';
import { WeaDebugRouteMenu, WeaLocaleProvider } from 'ecCom';

import Module from './index';
import '../portal4theme/components/theme/ecology9/style/index';

import PrintEmail from './components/PrintEmail';

const getLocaleLabel = WeaLocaleProvider.getLocaleLabel.bind(this, 'email');
WeaDebugRouteMenu.defaultProps.showRouteLev = 3;
const routing = new RouterStore();

const allStore = {
  routing,
  ...Module.store,
};

const browserHistory = useRouterHistory(createHashHistory)({
  queryKey: '_key',
  basename: '/',
});

const history = syncHistoryWithStore(browserHistory, allStore.routing);

const Home = props => props.children;

const Root = () => (
  <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@kz2gkc`} {...allStore}>
    <Router ecId={`${this && this.props && this.props.ecId || ''}_Router@rbdhsg`} history={history}>
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@mab2fy`} name="root" breadcrumbName="根路由" path="/" component={WeaDebugRouteMenu} onEnter={getLocaleLabel}>
        <IndexRedirect ecId={`${this && this.props && this.props.ecId || ''}_IndexRedirect@4tk3vy`} to="main/email/inbox?folderid=0&receivemail=true&receivemailid=0" />
        <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@lin7y9`} name="main" breadcrumbName="入口" path="main" component={Home}>
          { Module.Route }
        <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@32cjfc`} name="print" breadcrumbName="打印页面" path="printemail/printemail" component={PrintEmail} />
        </Route>
      </Route>
    </Router>
  </Provider>
);

ReactDOM.render(<Root ecId={`${this && this.props && this.props.ecId || ''}_Root@y8kkdr`} />, document.getElementById('container'));
